package com.onesports.intelligent.k12.polarlight.service.student;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.onesports.intelligent.k12.polarlight.domain.entity.student.UserStudentRel;
import com.onesports.intelligent.k12.polarlight.mapper.student.UserStudentRelMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author FPH
 * @since 2022年7月13日09:24:49
 */
@Service
public class UserStudentRelService extends ServiceImpl<UserStudentRelMapper, UserStudentRel> {

    /**
     * 通过userId获取studentId集合
     * @param userId
     * @return
     */
    public List<String> getStudentIdListByUserId(String userId){
        return list(new LambdaQueryWrapper<UserStudentRel>().eq(UserStudentRel::getUserId,userId))
                .stream().map(UserStudentRel::getStudentId).collect(Collectors.toList());
    }

    /**
     * 通过userId获取studentId集合
     * @param userIds
     * @return
     */
    public Map<String ,List<UserStudentRel>> getStudentIdListByUserIds(List<String> userIds){
        if(CollectionUtils.isEmpty(userIds)){
            return null;
        }
        return list(new LambdaQueryWrapper<UserStudentRel>().in(UserStudentRel::getUserId,userIds))
                .stream().collect(Collectors.groupingBy(UserStudentRel::getUserId));
    }
}
